package com.renzhebiao.lkang.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.plugins.Page;
import com.renzhebiao.lkang.base.BaseService;
import com.renzhebiao.lkang.entity.BennerPO;
import com.renzhebiao.lkang.mapper.BennerMapper;
import com.renzhebiao.lkang.page.PageDTO;
import com.renzhebiao.lkang.page.PaginationDTO;
import com.renzhebiao.lkang.query.BennerQuery;
import com.renzhebiao.lkang.request.RequestCache;
import com.renzhebiao.lkang.service.IBennerService;
import com.renzhebiao.lkang.utils.BeanCopys;

/**
 * <p>
 * 首页（轮播） 服务实现类
 * </p>
 *
 * @author renzhebiao123
 * @since 2018-10-23
 */
@Service
public class BennerService extends BaseService<BennerPO> implements IBennerService {

    @Autowired
    BennerMapper bennerMapper;

    @Override
    public void add(BennerPO po) {
        po.allEx(RequestCache.userId());
        this.bennerMapper.insert(po);
    }

    @Override
    public void edit(BennerPO po) {
        po.updated(RequestCache.userId());
        this.bennerMapper.updateById(po);

    }

    @Override
    public void delete(Long id) {
        // this.bennerMapper.deleteById(id);
        this.deleteByLogic(id, BennerPO.class);
    }

    @Override
    public List<BennerPO> getBennerList(BennerQuery po) {
        return this.bennerMapper.selectByMap(BeanCopys.toMap(po));
    }

    @Override
    public BennerPO getBenner(Long id) {
        return this.bennerMapper.selectById(id);
    }

    @Override
    public PageDTO<BennerPO> getBennerByPage(PaginationDTO<BennerQuery, Void> paging) {
        Page<BennerPO> page = this.getPage(paging);
        // page.setOrderByField("b.orderNo"); // 用户的创建时间
        // page.setAsc(false);
        List<BennerPO> pos = this.bennerMapper.getBennerByPage(page, page.getCondition());
        return this.getPage(page, pos);
    }

}
